package com.itheima.service.impl.pms;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.mapper.pms.PmsSkuStockMapper;
import com.itheima.pojo.pms.PmsProduct;
import com.itheima.pojo.pms.PmsSkuStock;
import com.itheima.service.pms.PmsProductService;
import com.itheima.service.pms.PmsSkuStockService;
import com.itheima.utils.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;

import java.util.List;


@DubboService
public class PmsSkuStockServiceImpl extends ServiceImpl<PmsSkuStockMapper, PmsSkuStock> implements PmsSkuStockService {

    @DubboReference
    private PmsProductService productService;

    /**
     * 批量更新sku库存信息
     * @param skuStockList
     * @return
     */
    public void updateSku(List<PmsSkuStock> skuStockList, Integer pid) {

        //修改库存表数据
        this.updateBatchById(skuStockList);

    }

    /**
     * 根据商品ID及sku编码模糊搜索sku库存
     * @param keyword
     * @return
     */
    public List<PmsSkuStock> likeSkuStock(String keyword, Integer productId) {

        LambdaQueryWrapper<PmsSkuStock> lqw = new LambdaQueryWrapper<>();
        lqw.eq(PmsSkuStock::getProductId,productId)
                .like(StringUtils.isNotEmpty(keyword), PmsSkuStock::getSkuCode, keyword);
        List<PmsSkuStock> skuStocks = this.list(lqw);

        return skuStocks;
    }
}
